<template>
  <transition name="el-fade-in-linear">
    <div class="drawer"
         v-show="visible"
         :style="{position:position}"
         @click="$emit('close')">
      <div :class="['drawer-right',visible?'drawer-show':'']"
           :style="{'max-width':`${maxWidth}%`,'width':width}"
           @click.stop="$emit('bg')">
        <slot></slot>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    maxWidth: {
      type: Number,
      default: 30
    },
    width: String,
    position: {
      type: String,
      default: 'fixed'
    }
  }
}
</script>

<style lang="scss" scoped>
.drawer {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-flow: row-reverse nowrap;
  &-right {
    position: relative;
    right: -100%;
    transition: all 2s;
    min-width: 300px;
    background: #fff;
    height: 100%;
    box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.3);
    overflow: auto;
  }
  &-show {
    right: 0;
  }
}
</style>